using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Triggers : MonoBehaviour
{
    //private int f = 1;
    public GameObject go = GameObject.Find("Ghost");
    // Start is called before the first frame update
    private GameObject myGameObject;
    private CharacterController Ctrl;
    

    void Awake()
    {
        //myGameObject = GameObject.Find("Ghost");
    }
    void Start()
    {
        Ctrl = go.GetComponent<CharacterController>();
    }

    // Update is called once per frame
    void Update()
    {
        /*
        if (f == 0)
        {
            Debug.Log(f);
            go.transform.position = new Vector3(0, (float)1.08, 3);
            f = 1;
            this.transform.position = new Vector3(0, (float)1.08, 3);
        }
        */
        float horizontal = Input.GetAxis("Horizontal");
        float vertical = Input.GetAxis("Vertical");
        Vector3 dir = new Vector3(horizontal, 0, vertical);
        //transform.Translate(dir * 2 * Time.deltaTime);

    }
    private void OnTriggerEnter(Collider other)
    {

        //Awake();
        //GameObject go = GameObject.Find("Ghost");
        
        Ctrl.enabled = false;
        
        //GameObject go = GameObject.Find("Cube");
        //Transform trans = go.transform;
        // if (go != null)
        //  {
        //go.SetActive(false);
        Debug.Log(Ctrl.enabled);
        go.transform.position = new Vector3(-2, (float)1.08, 3);
        Ctrl.enabled = true;
        //go.transform.rotation = new Quaternion(2,2,2,2);
        
        //this.transform.position = new Vector3(0, (float)1.08, 3);
        // }

    }
    private void OnTriggerStay(Collider other)
    {
        //GameObject go = GameObject.Find("Ghost");
        //go.transform.position = new Vector3(0,(float)1.08,3);
        Awake();
        myGameObject.transform.position = new Vector3(-2, (float)1.08, 3);
    }
    private void OnTriggerExit(Collider other)
    {
        // GameObject go = GameObject.Find("Ghost");
        // go.transform.position = Vector3.zero;
        //Awake();
        //myGameObject.transform.position = new Vector3(-2, (float)1.08, 3);
    }
}
/*
        int i = 0;
        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            float a = pos.z;
            pos.z=a+(float)2.5;
            this.transform.position = pos;
            i = 1;
            jtime = timer;
            m_rigidBody.AddForce(Vector3.up * 4, ForceMode.Impulse);

        }
        else if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            float a = pos.z;
            pos.z = a - (float)2.5;
            this.transform.position = pos;
            i = 1;
            jtime = timer;
        }
        else if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            float a = pos.x;
            pos.x = a - (float)2.5;
            this.transform.position = pos;
            i = 1;
            jtime = timer;
        }
        else if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            float a = pos.x;
            pos.x = a + (float)2.5;
            this.transform.position = pos;
            i = 1;
            jtime = timer;
        }
        */

/*
   Vector3 pos = this.transform.position;


       foreach (BoxCollider child in green)
       {
           Bounds bounds = child.bounds;
   bool rendererIsInsideTheBox = bounds.Contains(pos);
           if (rendererIsInsideTheBox&&count==1)

       */
//m_jumpInput = false;
//timer += Time.deltaTime;

//Destroy(ri);
//Debug.Log("1");

//if (f == 1)
//{
/*
float horizontal = Input.GetAxis("Horizontal");
    float vertical = Input.GetAxis("Vertical");
    Vector3 dir = new(horizontal, 0, vertical);
    transform.rotation = Quaternion.LookRotation(dir);
    if (dir != Vector3.zero)
    {
        //transform.Translate(Vector3.forward * 2 * Time.deltaTime);
    }
//}
if (Input.GetKey(KeyCode.UpArrow)&&(Time.time - jtime) >= 1f)
{
    jtime = Time.time;
    transform.rotation = Quaternion.LookRotation(dir);
    //transform.position += Vector3.forward * 2 * Time.deltaTime;
    m_currentV = Mathf.Lerp(m_currentV, vertical, Time.deltaTime * 20.5f);
    transform.position += transform.forward * m_currentV *2 * Time.deltaTime;
    m_rigidBody.AddForce(Vector3.up * 4, ForceMode.Impulse);
    transform.Translate(Vector3.forward * 1f);
    Debug.Log(vertical);
}
pos = this.transform.position;
if (bounds2.Contains(pos))
{
    if (Input.GetKeyUp(KeyCode.UpArrow))
    {
        this.transform.position = new(0, 2, (float)8.5);
        //this.transform.position = new(0, 0, 0);
        f = 0;
        index = 1;
        m_rigidBody.AddForce(Vector3.up * 4, ForceMode.Impulse);
    }
}
if (bounds1.Contains(pos))
{
    if (Input.GetKey(KeyCode.RightArrow))
    {
        this.transform.position = new((float)-2.5, 2, (float)8.5);
        //this.transform.position = new(0, 0, 0);
        f = 0;
        index = 0;
    }
}
if (bounds3.Contains(pos))
{
    if (Input.GetKey(KeyCode.LeftArrow))
    {
        this.transform.position = new((float)2.5, 2, (float)8.5);
        //this.transform.position = new(0, 0, 0);
        f = 0;
        index = 0;
    }
}
if ( f==0)
{
    Moveup();
    //timer = 0;
}
*/